package com.tianze.library.view;

import android.app.Activity;
import android.view.Gravity;
import android.view.View;

import com.tianze.library.R;
import com.tianze.library.interFace.IPickView;
import com.tianze.library.listener.SingleClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by kingtami.
 */

public class SimplePopSheet extends PopSheet {

    public interface OnButtonClickListener {
        void onConfirm(int position);

        void onCancel();
    }

    private PickerView mPickerView;

    private List<IPickView> mDataList = new ArrayList<>();

    private OnButtonClickListener onButtonClickListener;

    public void setOnButtonClickListener(OnButtonClickListener paramListener) {
        this.onButtonClickListener = paramListener;
    }

    public SimplePopSheet(Activity activity, int gravity) {
        super(activity, gravity);
        setContentView(R.layout.tiza_common_sheet);
        setCancelable(false);
        initSubViews();
    }

    public SimplePopSheet(Activity activity){
        this(activity, Gravity.BOTTOM);
    }


    public void setData(List<IPickView> paramList){
        mDataList.clear();
        mDataList.addAll(paramList);
    }

    private void initSubViews() {
        mPickerView = findViewById(R.id.pickerView);
        mPickerView.setData(mDataList);
        findViewById(R.id.textViewCancel).setOnClickListener(new SingleClickListener() {
            @Override
            public void onSingleClick(View view) {
                if (null != onButtonClickListener) {
                    onButtonClickListener.onCancel();
                }
            }
        });

        findViewById(R.id.textViewConfirm).setOnClickListener(new SingleClickListener() {
            @Override
            public void onSingleClick(View view) {
                if (null != onButtonClickListener) {
                    onButtonClickListener.onConfirm(mPickerView.getSelected());
                }
            }
        });
    }

    public void setSelected(int position) {
        mPickerView.setSelected(position);
    }

    public void setSelected(String title) {
        mPickerView.setSelected(title);
    }

}
